<template>
  <div class="abc">
    <UploadExcel :on-success="handleSuccess"></UploadExcel>
  </div>
</template>

<script>
import {importEmployee} from '@/api/employees'
import {formatExcelDate} from '@/utils/index'
export default {
  name: 'import',

  data() {
    return {
      
    };
  },

  mounted() {
   
  },

  methods: {
     handleSuccess({results,header}){
      const mapInfo = {
        '入职日期': 'timeOfEntry',
        '手机号': 'mobile',
        '姓名': 'username',
        '转正日期': 'correctionTime',
        '工号': 'workNumber',
        '部门': 'departmentName',
        '聘用形式': 'formOfEmployment'
      }
  
     
      var newresults=results.map(item=>{
        var obj={}
        var abc=Object.keys(mapInfo)
        abc.forEach(key=>{
          var cnm=mapInfo[key]
          if(cnm==='timeOfEntry'||cnm==='correctionTime'){
            obj[cnm]=new Date(formatExcelDate(item[key]))
          }else{
            obj[cnm]=item[key]
          }
        })
        return obj
      })
      importEmployee(newresults)
    }
  },
};
</script>

<style lang="scss" scoped>
.abc{
  margin-top: 100px;
}
</style>